package com.slt.android.androidexplorationart;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by dp on 2018/3/15.
 *
 * createFromParcel 从序列化后的对象中创建原始数据
 * newArray 创建指定长度的原始数据对象数组
 * writeToParcel 将当前对象写入序列化结果中。几乎所有的flag都为0
 * describeContents 返回当前对象的内容描述，几乎所有情况都返回0
 */

public class Book implements Parcelable {

    public String name;
    public String autor;
    public int count;

    protected Book(Parcel in) {
        name = in.readString();
        autor = in.readString();
        count = in.readInt();
    }

    public static final Creator<Book> CREATOR = new Creator<Book>() {
        @Override
        public Book createFromParcel(Parcel in) {
            return new Book(in);
        }

        @Override
        public Book[] newArray(int size) {
            return new Book[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(autor);
        dest.writeInt(count);
    }
}
